#
# Copyright 2007 Jeffrey Palm
#

require 'net/http'
require 'CGI'

def scan(page,re,host)
  h = Net::HTTP.new(host, 80)
  resp, data = h.get(page, nil)
  if resp.message == "OK"
    as = data.split /<h/
    as.each do |x| 
      x.scan(re) { |y| yield y}
    end
  else
    puts "ERROR: #{resp}"
  end
end

def extractResult(host,page)
  res = 0
  scan(page, /id="result"[^>]*>([^<]+)</, host) do |result|
    res = result[0]
  end
  return res
end

def urlencode(s) 
  return CGI.escape(s)
end
